package cn.iocoder.yudao.module.knowledge.service.elecdatacontact;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.knowledge.controller.admin.elecdatacontact.vo.*;
import cn.iocoder.yudao.module.knowledge.dal.dataobject.elecdatacontact.ElecDataContactDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.knowledge.dal.mysql.elecdatacontact.ElecDataContactMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.knowledge.enums.ErrorCodeConstants.*;

/**
 * 用电信息 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class ElecDataContactServiceImpl implements ElecDataContactService {

    @Resource
    private ElecDataContactMapper elecDataContactMapper;

    @Override
    public Long createElecDataContact(ElecDataContactSaveReqVO createReqVO) {
        // 插入
        ElecDataContactDO elecDataContact = BeanUtils.toBean(createReqVO, ElecDataContactDO.class);
        elecDataContactMapper.insert(elecDataContact);

        // 返回
        return elecDataContact.getId();
    }

    @Override
    public void updateElecDataContact(ElecDataContactSaveReqVO updateReqVO) {
        // 校验存在
        validateElecDataContactExists(updateReqVO.getId());
        // 更新
        ElecDataContactDO updateObj = BeanUtils.toBean(updateReqVO, ElecDataContactDO.class);
        elecDataContactMapper.updateById(updateObj);
    }

    @Override
    public void deleteElecDataContact(Long id) {
        // 校验存在
        validateElecDataContactExists(id);
        // 删除
        elecDataContactMapper.deleteById(id);
    }

    @Override
        public void deleteElecDataContactListByIds(List<Long> ids) {
        // 删除
        elecDataContactMapper.deleteByIds(ids);
        }


    private void validateElecDataContactExists(Long id) {
        if (elecDataContactMapper.selectById(id) == null) {
            throw exception(ELEC_DATA_CONTACT_NOT_EXISTS);
        }
    }

    @Override
    public ElecDataContactDO getElecDataContact(Long id) {
        return elecDataContactMapper.selectById(id);
    }

    @Override
    public PageResult<ElecDataContactDO> getElecDataContactPage(ElecDataContactPageReqVO pageReqVO) {
        return elecDataContactMapper.selectPage(pageReqVO);
    }

}